import { getRandomElements, HostEnum, type CategoryItemType } from "~/utils";
import { getServerCache } from "../plugins/cache";

/** 随机获取热门搜索5个 */
export default defineEventHandler(async (event): Promise<CategoryItemType[]> => {
  const { hostName = HostEnum.localhost, count = 5 } = await readBody(event);
  const config = getServerCache().gameJsonDataSource[hostName];
  const { categoryJson = [] } = config || {};
  return getRandomElements(categoryJson, count);
});
